package com.gzy.wbapplication.modules.mine;


import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gzy.wbapplication.R;
import com.gzy.wbapplication.manager.AuthManager;
import com.gzy.wbapplication.model.User;

import static android.content.ContentValues.TAG;

/**
 * A simple {@link Fragment} subclass.
 */
public class MineFragment extends Fragment {


    public MineFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_mine, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        User user = AuthManager.loadUser(getContext());

        Log.e(TAG, "onCreate: " + user.getAvatar() );


        TextView tv_username = view.findViewById(R.id.tv_username);
        TextView tv_bio = view.findViewById(R.id.tv_bio);
        ImageView iv_avatar = view.findViewById(R.id.iv_avatar);
        tv_username.setText(user.getUsername());
        tv_bio.setText(user.getRole() + " " + user.getEmail());
        Glide.with(getContext())
                .load(user.getAvatar())
                .circleCrop()
                .into(iv_avatar);



        view.findViewById(R.id.tv_settings).setOnClickListener((v) -> {
            startActivity(new Intent(getContext(),SettingsActivity.class));
        });
    }
}
